package com.hjj.web;

import com.hjj.pojo.Employee;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;


@RestController
@RequestMapping(value = "employees")
public class controller {
	@Value("")
	@GetMapping
	public List list(){
		return Arrays.asList(new Employee(1,"小肥羊",10),new Employee(2,"肥牛",10));
	}
	@GetMapping("/{id}")
	public Employee queryById(@PathVariable("id")int id){
		System.out.println("查询单 = "+ id);
		return new Employee(id,"小肥羊",10);
	}

//	@RequestMapping(method = RequestMethod.POST)
	@PostMapping
	public Employee add(@ModelAttribute("employee")Employee employee){
		System.out.println("添加 = " + employee.getId());
		return employee;
	}

	@PutMapping
	public Employee update(@ModelAttribute("employee")Employee employee){
		System.out.println("修改 = " + employee.getId());
		return employee;
	}

	@DeleteMapping("/delete/{id}")
	public int delete(@PathVariable("id")int id, HttpServletRequest request){
		System.out.println("删除 ="+id);
		System.out.println("URI ="+request.getRequestURI());
		System.out.println("URL ="+request.getRequestURL());
		System.out.println("CONTEXTPath ="+request.getContextPath());
		System.out.println("ServletPath"+request.getServletPath());
		return id;
	}

}
